<meta title="会员等级">
<div class="p">
    <table
            id="userLevelsGrid"
            s='datac,nda'
            s-data="Smart.cleanJsonRef(S.get('/api/user-level/list'))"
            class="table table-stripped table-bordered">
        <tr>
            <th>名称</th>
            <th>升级条件</th>
            <th>权益</th>
            <th class="text-center">状态</th>
            <th class="text-right">操作</th>
        </tr>
        <tbody s="loop" s-data-filter="'results'">
        <tr s-loop-role="empty">
            <td colspan=5" class="alert alert-warning">
                暂无数据
            </td>
        </tr>
        <tr s-loop-role="row" s="row,datac">
            <td name="name"></td>
            <td></td>
            <td></td>
            <td class="text-center" s="tpl">
                <label class="label
                            {%
                                switch(this.status) {
                                    case 'VALID': out.print('label-success'); break;
                                    case 'INVALID': out.print('label-default'); break;
                                    default: out.print('label-danger');break;
                                }
                            %}
                        ">{%=this.statusTitle%}</label>
            </td>
            <td s="tpl" class="text-right">
                {%if(this.status == 'VALID') {%}
                <input autocomplete="off" type="button" s-click="setStatus(this, 'INVALID')" class="btn btn-xs btn-warning btn-outline" value="设为不可用"/>
                {%} else {%}
                <input autocomplete="off" type="button" s-click="setStatus(this, 'VALID')" class="btn btn-xs btn-danger btn-outline" value="设为可用"/>
                {%}%}
                <input autocomplete="off" type="button" s-click="setStatus(this, 'DELETED')" class="btn btn-xs btn-danger btn-outline" value="删除"/>
            </td>
        </tr>
        </tbody>
        <tfoot>
        <tr>
            <td colspan="5" class="text-right">
                <ul s="pagination" id="sellerPagination"
                    s-pagination="{action:function(){$page.node.val(this); $userLevelsGrid.refresh()}}"
                    class="pagination pagination-sm">
                </ul>
                共有<span name="total"></span>个数据
            </td>
        </tr>
        </tfoot>
    </table>
</div>
<script type="text/javascript">
    function add() {
        S.popupOpen("/user-level/user-level-add.html").done(function(rs) {
            rs && $userLevelsGrid.refresh()
        })
    }

    function setStatus($this, status) {
        var data = $this.parent().data();
        S.confirm("确认操作吗?").done(function() {
            S.put("/api/user-level/status/" + data.id + "-" + status).done(function() {
                $userLevelsGrid.refresh()
            })
        })
    }

</script>